package com.cyh.asm;

import com.cyh.asm.bean.User;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author CYH
 */
public class EntranceClass extends ClassLoader{
    public static void main(String[] args) {
       /* try {
            ClassReader cr = new ClassReader(User.class.getName());
            ClassWriter cw = new ClassWriter(cr,ClassWriter.COMPUTE_FRAMES);
            MyVisitor myVisitor = new MyVisitor(cw);

            cr.accept(myVisitor,ClassReader.EXPAND_FRAMES);
            byte[] bytes = cw.toByteArray();
            EntranceClass ent = new EntranceClass();
            Class<?> aClass = ent.defineClass("com.cyh.asm.bean.User", bytes, 0, bytes.length);
            Object o = aClass.newInstance();
            Method method = aClass.getMethod("setAge", short.class);
            method.invoke(o, (short)12);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }*/
       User user = new User();
       user.setAge((short) 12);
    }

    public native String ks();


}
